//
//  BMHDBManager.m
//  BMHVideoMain
//
//  Created by 陈宪栋 on 2017/4/10.
//  Copyright © 2017年 Baomihua. All rights reserved.
//

#import "BMHDBManager.h"
#import "BMHDBManager+SearchRecord.h"
#import <UtilsMacro.h>
#import <FMDB.h>

NSString *const kDatabaseName = @"baomihua.sqlite3";

@implementation BMHDBManager
+(instancetype)sharedManager{
    static dispatch_once_t onceToken;
    static BMHDBManager *instance;
    dispatch_once(&onceToken, ^{
        instance = [[self alloc]init];
        [instance getDatabase];
        [instance createSearchRecordTable];
    });
    return instance;
}

/**
 *  获取数据库对象
 */
-(FMDatabase *)getDatabase
{
    NSString *dbFilePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:kDatabaseName];
    FMDatabase *db = [FMDatabase databaseWithPath:dbFilePath] ;
    if ([db open]) {
        return db;
    }else{
        BMHLog(@"数据库打开失败");
        return nil;
    }
}

@end
